
import Vue from 'vue'
import VueRouter, { RouteConfig, Route, NavigationGuard, NavigationGuardNext } from 'vue-router'
import Component from 'vue-class-component';
import store from "@/store";


const OpenNames = [
    "Reload",
    "Test1",
]


@Component
export class PageBefore extends Vue {

    IMReady: any;

    onLoad_Login(callback: (errorHost?: boolean) => void) {
        if (this.$user.isLogin) {
            callback();
            return;
        }
        

        let token = this.$user.getToken();
        if (!token) {
            callback(true);
            return;
        }
    }


    before(to: Route, from: Route, next: NavigationGuardNext) {
        this.beforeVerify(to, from, next);
    }

    beforeVerify(to: Route, from: Route, next: NavigationGuardNext) {
        if (__DEV__) {
            console.log(from, to);
        }
        let fromName = from.name;
        let toName = to.name;
        if (!toName) {
            return;
        }
        
        next();
        // if (toName == "Login") {
        //     this.$userHelper.clearLoginInfo();
        //     next();
        //     return;
        // }
        // if (OpenNames.indexOf(toName) >= 0) {
        //     next()
        //     return
        // }
        // this.onLoad_Login((error) => {
        //     if (error) {
        //         this.$userHelper.clearLoginInfo();
        //         next({ name: "Login" });
        //         return;
        //     }

        //     next();
        // });
    }

}